package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.entity.GongYingShangUser;
import com.ruoyi.system.domain.CangKu;
import com.ruoyi.system.mapper.CangKuMapper;
import com.ruoyi.system.service.ICangKuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 仓库信息 服务实现类
 * </p>
 *
 * @author qubaofeng
 * @since 2025-02-09
 */
@Service
public class CangKuServiceImpl extends ServiceImpl<CangKuMapper, CangKu> implements ICangKuService {

    @Override
    public List<CangKu> selectUserList(CangKu user) {
        return baseMapper.selectUserList(user);
    }

    @Override
    public CangKu selectUserById(Long userId) {
        return this.baseMapper.selectById(userId);
    }

    @Override
    public boolean haveUserName(CangKu user) {
        CangKu dangkouUser = this.baseMapper.selectByUserName(user.getName());
        return dangkouUser!=null;
    }

    @Override
    public int insertUser(CangKu user) {
        int row = baseMapper.insert(user);
        return row;
    }


    @Override
    public int deleteUserByIds(Long[] userIds) {
        for (Long id : userIds){
            CangKu param = new CangKu();
            param.setId(id);
            param.setDelFlag("2");
            this.baseMapper.updateById(param);
        }
        return 1;
    }

    @Override
    public CangKu selectUserByName(String username) {
        LambdaQueryWrapper<CangKu> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CangKu::getName, username);
        wrapper.eq(CangKu::getDelFlag, 0);
        return baseMapper.selectOne(wrapper, false);
    }
}
